﻿/// <reference path="_namespace.js" />
/// <reference path="../windows/FlyoutWindow.js" />
/// <reference path="IMenuItemContainer.js" />

/*****************************************************************************
Ajax library class definition. Kevin Robinson 2006.
Class: ajax.components.Menu
/*****************************************************************************/

ajax.lang.addNamespace("ajax.components");

// Menu Constructor
//-----------------------------------------------------------------------------
ajax.components.Menu = function(doc, sLayerName, w, h, parentNode)
{    
    ajax.components.Menu.superConstructor.call(this, doc, sLayerName, w, h, parentNode);
        
    
    this.load(); // creates all elements right now, which we need in order to pass content node to MenuItemContainer.
    
    // Create MenuItems Container
    this.menuItems  = ajax.lang.safeNew("ajax.components.MenuItemContainer", doc, this, this.content);
    // Create our own onItemSelected event
    this.getEvent(this.window, "onItemSelected");
    
    
    // Create our own delegate to recieve events from the MenuItemContainer and pass them on 
    // to OUR clients but with US as context
    this.onItemSelectedDelegate = function(args)
    {
        // Basically fire our own onItemSelected event, using US as context and add in the current
        // "this" pointer to the args list.
        args.menuItemContainer = this;
        var self = this.parentObject;
        self.onItemSelected.call(self, args);        
    }
    this.menuItems.getEvent(this.window, "onItemSelected").addListener(this.onItemSelectedDelegate);        	
}
//-----------------------------------------------------------------------------
ajax.lang.extend("ajax.components.Menu", "ajax.windows.FlyoutWindow"); // Inherit
ajax.lang.supports("ajax.components.Menu", "ajax.components.IMenuItemContainer"); // Interface
if ($getDesignMode())
    ajax.components.Menu.prototype = ajax.windows.FlyoutWindow.prototype;
//-----------------------------------------------------------------------------

// Overrides
//-----------------------------------------------------------------------------
ajax.components.Menu.prototype.create = function()
{    
    // Call the superclass create
    ajax.components.Menu.superClass.create.call(this);        
    
    // Set styling to be that of a menu
    this.layer.style.backgroundImage    = "url('" + ajax.getDomainPath() + "/images/menu_back.gif')";
    this.layer.style.backgroundRepeat   = "repeat-y";
    this.layer.style.visibility         = "hidden";
};

//-----------------------------------------------------------------------------
// Support the MenuItemContainer Interface as we say we will
ajax.components.Menu.prototype.add_itemSelected       = function(handler){ this.getEvent(this.getWindow(), "onItemSelected").addListener(handler); };
ajax.components.Menu.prototype.remove_itemSelected    = function(handler){ this.getEvent(this.getWindow(), "onItemSelected").removeListener(handler); };

ajax.components.Menu.prototype.addMenuItem = function(menuItem)
{
    return this.menuItems.addMenuItem(menuItem);
}
ajax.components.Menu.prototype.removeMenuItem = function(menuItem)
{
    return this.menuItems.removeMenuItem(menuItem);
}
ajax.components.Menu.prototype.getMenuItem = function(sKey)
{
    return this.menuItems.getMenuItem(sKey);
}


//-----------------------------------------------------------------------------
ajax.components.Menu.prototype.setWideBackground = function(val)
{
    if (val)
        this.layer.style.backgroundImage    = "url('" + ajax.getDomainPath() + "/images/menu_back_wide.gif')";
    else
        this.layer.style.backgroundImage    = "url('" + ajax.getDomainPath() + "/images/menu_back.gif')";
}

//-----------------------------------------------------------------------------
ajax.components.Menu.prototype.toString = function()
{
    return "ajax.components.Menu";
}
//-----------------------------------------------------------------------------
ajax.components.Menu.prototype.toClassName = function()
{    
    return ajax.lang.getClassName("ajax.components.Menu");
}

//-----------------------------------------------------------------------------
ajax.components.Menu.cast = function(obj)
{///<returns type="ajax.components.Menu"/>
    return obj;
}